<?php
/**
 * Copyright (C) 2013  Artur Tolstenco
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


class Oauth2_Model_ReceivedData {
	/**
	 * 
	 * @var array[int]array[int]string
	 */
	private $data;
	/**
	 *
	 * @var array[int]array[int]Oauth2_Model_TokenPart|string
	 */
	private $error;
	
	public function __construct() {
		$this->data = array();
		$this->error = array();
		
	}
	
	public function addData(Oauth2_Model_TokenPart $t, $str) {
		$this->data[] = array($t->getContactUri(), $str);
	}
	
	public function addError(Oauth2_Model_TokenPart $t, $str) {
		$this->error[] = array($t, $str);
	}
	
	/**
	 * 
	 * @return array[int]array[int]Oauth2_Model_TokenPart|string
	 */
	public function getData() {
		return $this->data;
	}
	/**
	 * 
	 * @return array[int]array[int]Oauth2_Model_TokenPart|string
	 */
	public function getErrors() {
		return $this->error;
	}
	
	/**
	 * 
	 * @param array $a
	 * @return NULL|string
	 */
	public static function getDescription(array $a) {
		if (!is_array($a) || count($a) != 2)
			return null;
		return $a[1];
	}
	
	
	
	/**
	 * 
	 * @param array $a
	 * @return NULL|array[int]scopes
	 */
	public static function getScopes(array $a) {
		$tp = Oauth2_Model_ReceivedData::getTokenPart($a);
		if ($tp == null)
			return null;
		return $tp->getScopes();
	}
	
	/**
	 *
	 * @param array $a
	 * @return NULL|Oauth2_Model_TokenPart
	 */
	private static function getTokenPart(array $a) {
		if (!is_array($a) || count($a) != 2)
			return null;
		return $a[0];
	}
}

